<template>
  <div class="box">
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm" style="text-align: left">
      <el-form-item label="店铺名称" prop="storeName">
        <el-input v-model="ruleForm.storeName"></el-input>
      </el-form-item>
      <el-form-item label="店铺地址" prop="storeAddress">
        <el-input v-model="ruleForm.storeAddress"></el-input>
      </el-form-item>
      <el-form-item label="联系电话" prop="storeTel">
        <el-input v-model="ruleForm.storeTel"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>

export default {
  name: "registerStore",
  data() {
    return {
      ruleForm: {
        storeName: '',
        storeAddress: '',
        storeTel: ''
      },
      rules: {
        storeName: [
          { required: true, message: '请输入店铺名称', trigger: 'blur' },
          { min: 3, max: 7, message: '长度在 2 到 15 个字符', trigger: 'blur' }
        ],
        storeAddress: [
          { required: true, message: '请输入地址', trigger: 'blur' }
        ],
        storeTel: [
          { required: true, message: '请输入电话号码', trigger: 'blur' }
        ]
      }
    };
  },
  methods: {
    submitForm(formName) {
      let _this = this
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.axios.post("/store/registerStore", this.ruleForm).then(response => {
            console.log(response)
            if (response.data.result) {

              _this.$message.success(response.data.message);
            } else {
              _this.$message.error("注册失败");
            }
          })
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  }
}
</script>

<style scoped>

.box{
  width: 70%;
  margin: auto;
  border: #333333 solid 1px;
  border-radius: 5px;
  padding: 20px;
}
</style>
